﻿@page
@{
    ViewData["Title"] = "角色修改/添加";
    Layout = "~/Pages/Admin/_Layout.cshtml";
}

<div id="app">
    <form class="layui-form form-cus" action="" lay-filter="forms">
       
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.name" name="Name" lay-verify="required" lay-verType="tips"
                       autocomplete="off" placeholder="请输入角色名称" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea v-model="m.remarks" style="min-height: 60px;" name="Summary"
                          class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item layui-cur-submit">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submit" id="submit">
                    <i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-hide"></i>提交
                </button>
                <button type="button" class="layui-btn layui-btn-primary btn-open-close">取消</button>
            </div>
        </div>
    </form>
</div>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            m: {}
        }
    });
        layui.use(['layer', 'jquery', 'common', 'form'], function () {
            var form = layui.form, $ = layui.$, os = layui.common;


            var index = parent.layer.getFrameIndex(window.name);

            var oc = {
                init(){

                    if(os.getUrlParam('id') != null) {

                        //查询用户信息
                        os.ajax('api/admin/sysrole/get',
                            { id: os.getUrlParam('id') },
                            function (res) {

                                if (res.code == 1) {
                                    vm.m = res.data;
                                 
                                } else {
                                    os.error(res.msg);
                                }
                               
                            }, 'get');
                     }
                  }
            }



            oc.init()

        //监听提交
        form.on('submit(submit)', function (data) {
           
            $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
            var urls = "api/admin/sysrole/add";

            if (os.getUrlParam('id') != null) {
                urls = "api/admin/sysrole/update";
            }
            os.ajax(urls, vm.m, function (res) {
                $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                if (res.code === 1) {
                    parent.layer.close(index);
                    //刷新父页面的数据
                    $('button[data-type="reload"]', window.parent.document).click();
                } else {
                    os.error(res.msg);
                }
            });
            return false;
        });



        $(".btn-open-close").on('click', function () {
            parent.layer.close(index);
        });


       

    });
</script>
